﻿#ifndef GUIDEMANAGER_H
#define GUIDEMANAGER_H

#include <QWidget>
#include <QPointer>
#include <QList>
#include <QKeyEvent>
#include <functional>
#include "GuideBubble.h"

using GuideStepBefore_fn = std::function<void()>;

struct GuideStep {
    QWidget *targetWidget;
    QString text;
    GuideStepBefore_fn onBeforeStep;
};

class GuideManager : public QWidget
{
    Q_OBJECT
public:
    explicit GuideManager(QWidget *parent = nullptr);
    ~GuideManager();

    void addStep(QWidget *widget, const QString &text, GuideStepBefore_fn before=nullptr);
    void start();

signals:
    void finished();

protected:
    void showEvent(QShowEvent* event) override;
    void paintEvent(QPaintEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void resizeEvent(QResizeEvent *event) override;
    void keyPressEvent(QKeyEvent *event) override;
    bool eventFilter(QObject *watched, QEvent *event) override;

private:
    void safeShowStep();
    void showCurrentStep();
    void moveToFinePos();
    QRect targetRectFor(QWidget *widget);

private:
    QList<GuideStep> m_steps;
    int m_currentIndex = -1;
    QRect m_highlightRect;
    QRect m_targetRect;
    GuideBubble *m_bubble = nullptr;
    bool m_isFirstShowBubble = true;  // 是否第一次显示气泡（第一次直接显示即可，不要动画）
};

#endif // GUIDEMANAGER_H
